<%--
  Created by IntelliJ IDEA.
  User: lanou
  Date: 18/1/25
  Time: 下午7:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="p" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">


    <title>商城</title>

    <!-- Bootstrap core CSS -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">


    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>

</head>

<body>

<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/index">幻想天堂</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">

            <div class="navbar-right" >
                <a  class="navbar-brand" href="/success/buycar">${sessionScope.get('name')}</a>
                <a  class="navbar-brand" href="#">账户余额：${sessionScope.get('money')}</a>

                <input class='btn btn-success' type='button' id='exit' value='退出'>
            </div>


        </div><!--/.navbar-collapse -->
    </div>
</nav>
<div class="container">

    <div class="row row-offcanvas row-offcanvas-right">

        <div class="col-xs-12 col-sm-9">
            <p class="pull-right visible-xs">
                <button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas">Toggle nav</button>
            </p>
            <div class="jumbotron">
                <h1>Hello, 穷逼!</h1>
                <p>来这体验一下有钱人是怎么买东西的吧。</p>
            </div>
            <div class="row">
                <p:forEach var="d" items="${sessionScope.get('dlist')}">
                <div class="col-xs-6 col-lg-4">
                    <img style="width: 200px;height: 150px" src="${d.url}">
                    <h2>${d.dname}</h2>
                    <p>${d.dabout}</p>
                    ￥${d.maney}<br>
                    <%--<input type="hidden" value="${d.id}" class="id">--%>

                    <p><input type="button" did="${d.id}" class="btn btn-default" buy="buy" value="购买&raquo;"></p>
                </div><!--/.col-xs-6.col-lg-4-->
                </p:forEach>

            </div><!--/row-->
        </div><!--/.col-xs-12.col-sm-9-->


    </div><!--/row-->



    <footer>
        <p>&copy; Company 2018</p>
    </footer>

</div><!--/.container-->


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>

    $(function () {
        $("[buy='buy']").on("click",function () {
            var did = $(this).attr("did");
            $.ajax({
                type:'post',
                url:'/success/buy',
                data:{did:did},
                success:function (data) {
                    if(data == ""){
                        alert("购买成功！");
                        window.location.reload();
                    }else {
                        alert(data.data);
                    }
                }
            })
        })
        $(document).ready(function () {
            $("#exit").on("click",function () {
                $.ajax({
                    type:'post',
                    url:'/exit',
                    success:function () {
                        window.location.reload();
                    },
                    error:function () {
                        alert("shibai");
                    }
                })
            })

        })
    })
</script>
</body>
</html>
